package com.zzq.my.jetpacks.jectpackapp.ui.dzfs

import androidx.fragment.app.Fragment
import by.kirich1409.viewbindingdelegate.viewBinding
import com.aisier.architecture.base.BaseActivity
import com.androidkun.xtablayout.XTabLayout
import com.zzq.my.jetpacks.jectpackapp.R
import com.zzq.my.jetpacks.jectpackapp.bean.AutoSelectItem
import com.zzq.my.jetpacks.jectpackapp.databinding.ShopIncomingActivityAccountRecordBinding
import com.zzq.my.jetpacks.jectpackapp.ui.fragment.AFragment
import com.zzq.my.jetpacks.jectpackapp.ui.fragment.BFragment
import com.zzq.my.jetpacks.jectpackapp.utils.DropDownViewManager
import com.zzq.my.jetpacks.jectpackapp.view.DropDownView

/**
 * 描述：账号明细
 * 作者：zhuangzeqin
 * 时间: 2022/9/5-9:40
 * 邮箱：zzq@eeepay.cn
 * 备注:
 */
class AccountRecordAct : BaseActivity(R.layout.shop_incoming_activity_account_record) {
    private val binding by viewBinding(ShopIncomingActivityAccountRecordBinding::bind)
    private var mFragmentTab: ArrayList<Fragment>? = null
    private var autoSelectItemList: MutableList<AutoSelectItem> = mutableListOf()
    private var listMap: HashMap<String, String> = hashMapOf()//筛选条件
    private lateinit var dropDownView: DropDownView
    private lateinit var fragmentTabAdapter: FragmentAdapter

    private var accountType = AccountTypeConstant.IN//默认是第一个 入账记录
    override fun initData() {
        autoSelectItemList.clear()
        autoSelectItemList.add(AutoSelectItem("激活活动", "1", true))
        autoSelectItemList.add(AutoSelectItem("会员活动", "2"))
    }

    override fun initView() {
        dropDownView = binding.dropDownView
        initViewPager()
    }

    override fun eventOnClick() {
        //筛选
        binding.tvFilter.setOnClickListener {
            if (accountType == AccountTypeConstant.IN) {
                DropDownViewManager.accountInFilter(
                    mContext,
                    dropDownView,
                    binding.tvFilter,
                    autoSelectItemList,
                    listMap,
                    object : DropDownViewManager.OnPopupWindowOnClickListener {
                        override fun onPopupWindowOnClick(dates: Map<String, String>) {
//                    通知刷新
//                    pageNo=1;
//                    refreshLayout.autoRefresh();
                        }
                    })
            }else
            {
                DropDownViewManager.accountOutFilter(
                    mContext,
                    dropDownView,
                    binding.tvFilter,
                    listMap,
                    object : DropDownViewManager.OnPopupWindowOnClickListener {
                        override fun onPopupWindowOnClick(dates: Map<String, String>) {
//                    通知刷新
//                    pageNo=1;
//                    refreshLayout.autoRefresh();
                        }
                    })
            }
        }

    }

    private fun initViewPager() {
        mFragmentTab = ArrayList()
        mFragmentTab?.let {
            it.add(AccountInRecordFragment.newInstance())
            it.add(AccountOutRecordFragment.newInstance())
        }
        val titles: MutableList<String> = ArrayList()
        titles.add("入账记录")
        titles.add("提现记录")
        fragmentTabAdapter = FragmentAdapter(supportFragmentManager, mFragmentTab, titles)
        binding.viewPager.adapter = fragmentTabAdapter
        binding.viewPager.offscreenPageLimit = 1
        //将TabLayout和ViewPager关联起来。
        binding.XTabLayout.setupWithViewPager(binding.viewPager)
        binding.XTabLayout.setOnTabSelectedListener(object : XTabLayout.OnTabSelectedListener {
            override fun onTabSelected(tab: XTabLayout.Tab?) {
                tab?:return
                val index = tab.position
                accountType = if (index == 0) AccountTypeConstant.IN else AccountTypeConstant.OUT
                binding.viewPager.currentItem = index
                dropDownView.collapseDropDown()
            }

            override fun onTabUnselected(tab: XTabLayout.Tab?) {

            }

            override fun onTabReselected(tab: XTabLayout.Tab?) {

            }
        })


    }
}